<template>
  <div>
    用户列表
    <div v-for="(user, index) in userList" class="user" @click="toPage(user)">
      <div>{{ user.uid }}</div>
      <div>{{ user.phone }}</div>
      <div>
        <img :src="user.avatar" alt="">
      </div>
    </div>
  </div>
</template>

<script>
// import axios from 'Axios'
export default{
  data() {
    return {
      // 接口参数对象
      params: {
        page: 0,
      },
      userList: [], // 用户列表      
    }
  },
  created() {
    // 页面初始化的时候加载用户列表
    // this.getUserList()
  },
  methods: {
    // 获取用户列表
    getUserList() {
      const user_json = localStorage.getItem('user')
      const user = JSON.parse(user_json)
      if (!(user && user.token)) {
        alert('请登录')
        this.$router.push('/login')
        return
      }
      this.params.page ++
      this.$request({
        headers: {
          uid: user.uid,
          token: user.token,
        },
        url: 'http://119.23.34.123:8087/parents.user/userList',
        data: this.params,
        method: 'post',
      }).then(({ data: res }) => {
        if (!res.status) {
          alert(res.msg)
          if (res.code === 10000) {
            this.$router.push('/login')
          }
          return
        }
        const userList = res.data.data
        this.userList = userList
      })
    },
    toPage(user) {
      const { uid, phone, create_time_text } = user
      const query = { uid, phone, create_time_text }
      
      // this.$router.push({ name: 'userinfo', query })
      this.$router.replace({ name: 'userinfo', query })
    },
  },
}
</script>

<style scoped>
.user{
  margin: 15px;;
}
img{
  height: 50px;
}
</style>
